/*******************************************************************************
* Copyright (c) 2010, 2018 西安秦晔信息科技有限公司
* Licensed under the Apache License, Version 2.0 (the "License");
*    you may not use this file except in compliance with the License.
*    You may obtain a copy of the License at
*
*       http://www.apache.org/licenses/LICENSE-2.0
*
*    Unless required by applicable law or agreed to in writing, software
*    distributed under the License is distributed on an "AS IS" BASIS,
*    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*    See the License for the specific language governing permissions and
*    limitations under the License.
*******************************************************************************/
package com.qinyeit.serviceapp.service.dishes.impl;

import com.qinyeit.serviceapp.entity.Dishes;
import com.qinyeit.serviceapp.exception.BusinessRunTimeException;
import com.qinyeit.serviceapp.utils.SearchUtils;
import com.qinyetech.springstage.core.entity.search.Searchable;
import com.qinyetech.springstage.core.lang.QyMap;
import com.qinyetech.springstage.core.repository.jdbc.PageNamedParameterJdbcTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.qinyetech.springstage.core.service.BaseService;
import com.qinyeit.serviceapp.entity.DishesSpecification;
import com.qinyeit.serviceapp.repository.dishes.DishesSpecificationRepository;
import com.qinyeit.serviceapp.service.dishes.DishesSpecificationService;

import java.util.List;
import java.util.Map;

/** 
 * ClassName: DishesSpecificationServiceImpl <br/> 
 * Function: 菜品规格 业务实现 <br/> 
 * date: 2018-11-23 11:06:05 <br/> 
 * 
 * @author liuwenjin
 * @version 1.0
 * @since JDK 1.8
 */
@Service
@Transactional
public class DishesSpecificationServiceImpl extends BaseService<DishesSpecification, Long> implements DishesSpecificationService {


	@Autowired
	private DishesSpecificationRepository dishesSpecificationRepository;
	@Autowired
	private PageNamedParameterJdbcTemplate jdbcTemplate;


	@Override
	public List<Map<String,Object>> getDishesBySpecification(Long merchantGroupId, DishesSpecification specification) {
		String sql = "SELECT d.id,d.name,ds.id as store_id,ds.name as store_name,d.price,d.vip_price from dishes_specification_relations dsr\n" +
				"LEFT JOIN dishess d  on d.id = dsr.dishes_id\n" +
				"LEFT JOIN dishes_stores ds on ds.id = d.store_id\n" +
				"where dsr.spec_id = :spec_id and dsr.merchant_group_id = :merchantGroupId";
		QyMap map = QyMap.map("spec_id",specification.getId())
				.setv("merchantGroupId",merchantGroupId);
		List<Map<String,Object>> mapList = jdbcTemplate.queryForList(sql,map);
		return mapList;
	}
}